package com.ruoyi.web.controller.system.yaoke;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.SysPost;
import com.ruoyi.system.domain.yaoke.SysBuilding;
import com.ruoyi.system.service.yaoke.ISysBuildingService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 *  楼宇-楼栋管理
 * 
 * @author yaoke
 */
@RestController
@RequestMapping("/system/building")
public class SysBuildingController extends BaseController
{
    @Autowired
    private ISysBuildingService buildingService;

    /**
     * 获取列表
     */
    @PreAuthorize("@ss.hasPermi('system:building:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysBuilding building)
    {
        startPage();
        List<SysBuilding> list = buildingService.selectBuildingList(building);
        return getDataTable(list);
    }
    
    @Log(title = "楼栋管理", businessType = BusinessType.EXPORT)
    //@PreAuthorize("@ss.hasPermi('system:building:export')")
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysBuilding building)
    {
        List<SysBuilding> list = buildingService.selectBuildingList(building);
        ExcelUtil<SysBuilding> util = new ExcelUtil<SysBuilding>(SysBuilding.class);
        util.exportExcel(response, list, "楼栋数据");
    }

    /**
     * 根据岗位编号获取详细信息
     */
    //@PreAuthorize("@ss.hasPermi('system:building:query')")
    @GetMapping(value = "/{banId}")
    public AjaxResult getInfo(@PathVariable Long banId)
    {
        return success(buildingService.selectBuildingById(banId));
    }

    /**
     * 新增岗位
     */
    @PreAuthorize("@ss.hasPermi('system:building:add')")
    @Log(title = "管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@Validated @RequestBody SysBuilding building)
    {
        return toAjax(buildingService.insertBuilding(building));
    }

    /**
     * 修改岗位
     */
    @PreAuthorize("@ss.hasPermi('system:post:edit')")
    @Log(title = "管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@Validated @RequestBody SysBuilding building)
    {
        return toAjax(buildingService.updateBuilding(building));
    }

    /**
     * 删除岗位
     */
    @PreAuthorize("@ss.hasPermi('system:post:remove')")
    @Log(title = "岗位管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{postIds}")
    public AjaxResult remove(@PathVariable Long[] postIds)
    {
        return toAjax(buildingService.deleteBuildingByIds(postIds));
    }

    /**
     * 获取选择框列表
     */
    @GetMapping("/optionselect")
    public AjaxResult optionselect()
    {
        List<SysBuilding> posts = buildingService.selectBuildingAll();
        return success(posts);
    }
}
